package router

import (
	auth_handles "github.com/baker-yuan/go-blog/auth/adapter/http"
	menuRep "github.com/baker-yuan/go-blog/auth/infrastructure/repository"
	"github.com/baker-yuan/go-blog/blog/adapter/http/blog_handles"
	articleRep "github.com/baker-yuan/go-blog/blog/infrastructure/repository"
	"github.com/baker-yuan/go-blog/middleware"
	"github.com/baker-yuan/go-blog/user/adapter/http/user_handles"
	userRep "github.com/baker-yuan/go-blog/user/infrastructure/repository"
	"github.com/gin-gonic/gin"
	swaggerFiles "github.com/swaggo/files"     // swagger embed files
	ginSwagger "github.com/swaggo/gin-swagger" // gin-swagger middleware

	_ "github.com/baker-yuan/go-blog/docs" // docs is generated by Swag CLI, you have to import it.
)

//	@title			go+vue单体博客
//	@version		1.0
//	@description	This is a sample server celler server.
//	@termsOfService	http://swagger.io/terms/

//	@contact.name	API Support
//	@contact.url	http://www.swagger.io/support
//	@contact.email	support@swagger.io

//	@license.name	Apache 2.0
//	@license.url	http://www.apache.org/licenses/LICENSE-2.0.html

//	@host		localhost:8080
//	@BasePath	/api

//	@securityDefinitions.basic	BasicAuth

//	@externalDocs.description	OpenAPI
//	@externalDocs.url			https://swagger.io/resources/open-api/

func InitRouter(middlewares ...gin.HandlerFunc) *gin.Engine {

	router := gin.Default()
	router.Use(middlewares...)

	router.GET("/ping", func(c *gin.Context) {
		c.JSON(200, gin.H{
			"message": "pong",
		})
	})

	indexRouter := router.Group("/api/")
	indexRouter.Use(
		middleware.RecoveryMiddleware(),
	)
	{
		blog_handles.ArticleRegister(indexRouter, &articleRep.ArticleRepoImpl{})
		// controller.RoleRegister(indexRouter)
		// controller.BlogInfoRegister(indexRouter)
		user_handles.UserAuthRegister(indexRouter, &userRep.UserRepoImpl{})
		auth_handles.MenuRegister(indexRouter, &menuRep.MenuRepoImpl{})
		// controller.CensusRegister(indexRouter)
	}

	router.GET("/swagger/*any", ginSwagger.WrapHandler(swaggerFiles.Handler))

	return router
}
